# class Solution:
#     def addStrings(self, num1: str, num2: str) -> str:
#         res = ""
#         i, j, carry = len(num1) - 1, len(num2) - 1, 0
#         while i >= 0 or j >= 0:
#             n1 = int(num1[i]) if i >= 0 else 0
#             n2 = int(num2[j]) if j >= 0 else 0
#             tmp = n1 + n2 + carry
#             carry = tmp // 10
#             res = str(tmp % 10) + res
#             i, j = i - 1, j - 1
#         return "1" + res if carry else res
class Solution:
    def addString(self,num1:str,num2:str)->str:
        res=""
        i,j,carry=len(num1)-1,len(num2)-1,0
        while i>=0 or j>=0 or carry>0:
            if i>=0:
                n1=int(num1[i])
            else:
                n1=0
            if j>=0:
                n2=int(num2[j])
            else:
                n2=0
            tmp=n1+n2+carry
            carry=tmp//10
            res=str(tmp%10)+res
            i,j=i-1,j-1
        return res

if __name__=="__main__":
    num1="552"
    num2="975"
    S=Solution()
    res=S.addString(num1,num2)
    print(res)
